<?php
require_once 'pages/TMSListPage.inc';

class TMSCollectionPage extends TMSListPage {
/**
 * @var TCandyModel
 */	
	protected $_ioc_container_model_;
	
	public $FilterProperty;
	
	private $_path_;
	
	protected function filterOptions(THttpRequest $request){
		$result = parent::filterOptions($request);
		if (isset($request->container) && $this->FilterProperty)
			$result[$this->FilterProperty] = new TFilterOption($this->FilterProperty, TConditionType::C_EQUAL, $request->container); 
		return $result;
	}
	
	public function __get($nm){
		switch ($nm){
			case 'CreateLink':return $this->service->Url($this->Name().'/create',null,null,array('container'=>$this->request->container));break;
			case 'Path':{
				if (!isset($this->_path_))
					$this->_path_ = $this->service->CollectionPath($this->Name(),$this->request->container);
				return $this->_path_;
			}break;
			default:return parent::__get($nm);break;
		}
	}
	
	protected function processUrlParameters(array $parameters){
		if ($this->request instanceof THttpRequest)
			$parameters['container'] = $this->request->container;
		return $parameters;
	}
	
	public function ActionUrls(IItem $item){
		return array(
			'Edit'=>$this->service->Url($this->Name().'/item',null,null,array('container'=>$this->request->container,'id'=>$item->ItemId())),
			'Delete'=>$this->Url(null,'Delete',array('id'=>$item->ItemId()))
		);
	}	
}